////////////////////////////////////////////////////////////////////////////////
/// @file     slcd.c
/// @author   AE TEAM
/// @brief    THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////

// Define to prevent recursive inclusion
#define _SLCD_C_

// Files includes
#include "stdio.h"
#include "mm32l0136c.h"
#include "hal_slcd.h"

#include "slcd.h"
#define LSEREADTIMEOUT                  8000
#define LCD_COM_NUMBER      (4)
#define LCD_SEG_NUMBER      (25-3)

#define LCD_NUM_LEN1        6
#define LCD_NUM_LEN2        4

const uint32_t POW10[] = {1, 10, 100, 1000, 10000, 100000, 1000000};

const LCD_CODING_TypeDef LCD_CODE_Table[38] = {
    {' ', 0x00},
    {'0', 0x3F},
    {'1', 0x06},
    {'2', 0x5B},
    {'3', 0x4F},
    {'4', 0x66},
    {'5', 0x6D},
    {'6', 0x7D},
    {'7', 0x07},
    {'8', 0x7F},
    {'9', 0x6F},
    {'A', 0x77},
    {'b', 0x7C},
    {'c', 0x58},
    {'C', 0x39},
    {'d', 0x5E},
    {'E', 0x79},
    {'F', 0x71},
    {'g', 0x6F},
    {'H', 0x76},
    {'h', 0x74},
    {'i', 0x04},
    {'I', 0x30},
    {'J', 0x1E},
    {'l', 0x30},
    {'L', 0x38},
    {'n', 0x54},
    {'o', 0x5C},
    {'O', 0x3F},
    {'P', 0x73},
    {'q', 0x67},
    {'r', 0x50},
    {'S', 0x6D},
    {'t', 0x78},
    {'u', 0x1C},
    {'U', 0x3E},
    {'y', 0x6E},
    {'-', 0x40},
};
const char LCD_NAME_Table[LCD_COM_NUMBER][LCD_SEG_NUMBER][4] = {
    {"1D ", "DP1", "2D ", "DP2", "3D ", "DP3", "4D ", "C1 ", "C2 ", /*"W5 ", "L1 ",*/ "5F ",  "5A ", "6F ", "6A ", "7F ", "7A ", "S4 ", /*"S5 ",*/ "8F ", "8A ", "9F ", "9A ", "10F", "10A"},
    {"1E ", "1C ", "2E ", "2C ", "3E ", "3C ", "4E ", "4C ", "C3 ", /*"W4 ", "L2 ",*/ "5G ",  "5B ", "6G ", "6B ", "7G ", "7B ", "S3 ", /*"S6 ",*/ "8G ", "8B ", "9G ", "9B ", "10G", "10B"},
    {"1G ", "1B ", "2G ", "2B ", "3G ", "3B ", "4G ", "4B ", "T1 ", /*"W3 ", "L3 ",*/ "5E ",  "5C ", "6E ", "6C ", "7E ", "7C ", "S2 ", /*"S7 ",*/ "8E ", "8C ", "9E ", "9C ", "10E", "10C"},
    {"1F ", "1A ", "2F ", "2A ", "3F ", "3A ", "4F ", "4A ", "W1 ", /*"W2 ", "L4 ",*/ "5D ",  "DP5", "6D ", "DP6", "7D ", "DP7", "S1 ", /*"S8 ",*/ "8D ", "DP8", "9D ", "DP9", "10D", "S9 "},
};
const uint32_t LCD_SEG_Table[LCD_SEG_NUMBER][2] = {
    {0, SLCD_L3 },   /* PIN1  -> SCH_SLCDL0  -> PB8  -> L3  */
    {0, SLCD_L7 },   /* PIN2  -> SCH_SLCDL1  -> PA15 -> L7  */
    {0, SLCD_L6 },   /* PIN3  -> SCH_SLCDL2  -> PC10 -> L6  */
    {0, SLCD_L5 },   /* PIN4  -> SCH_SLCDL3  -> PC11 -> L5  */
    {0, SLCD_L4 },   /* PIN5  -> SCH_SLCDL4  -> PC12 -> L4  */
    {1, SLCD_L58},   /* PIN6  -> SCH_SLCDL5  -> PD6  -> L58 */
    {0, SLCD_L26},   /* PIN7  -> SCH_SLCDL6  -> PB1  -> L26 */
    {0, SLCD_L27},   /* PIN8  -> SCH_SLCDL7  -> PB0  -> L27 */
    {0, SLCD_L30},   /* PIN9  -> SCH_SLCDL8  -> PA7  -> L30 */

    {0, SLCD_L8 },   /* PIN16 -> SCH_SLCDL11 -> PD3  -> L8  */
    {0, SLCD_L9 },   /* PIN17 -> SCH_SLCDL12 -> PD2  -> L9  */
    {0, SLCD_L10},   /* PIN18 -> SCH_SLCDL13 -> PA12 -> L10 */
    {0, SLCD_L11},   /* PIN19 -> SCH_SLCDL14 -> PA11 -> L11 */
    {0, SLCD_L15},   /* PIN20 -> SCH_SLCDL15 -> PC9  -> L15 */
    {0, SLCD_L16},   /* PIN21 -> SCH_SLCDL16 -> PC8  -> L16 */
    {0, SLCD_L17},   /* PIN22 -> SCH_SLCDL17 -> PC7  -> L17 */

    {0, SLCD_L20},   /* PIN24 -> SCH_SLCDL19 -> PB14 -> L20 */
    {0, SLCD_L19},   /* PIN25 -> SCH_SLCDL20 -> PB15 -> L19 */
    {0, SLCD_L22},   /* PIN26 -> SCH_SLCDL21 -> PB12 -> L22 */
    {0, SLCD_L21},   /* PIN27 -> SCH_SLCDL22 -> PB13 -> L21 */
    {0, SLCD_L28},   /* PIN28 -> SCH_SLCDL23 -> PC5  -> L28 */
    {0, SLCD_L29},   /* PIN29 -> SCH_SLCDL24 -> PC4  -> L29 */
};
void LCD_Clear(void)
{
    SLCD->DR0  = 0;
    SLCD->DR1  = 0;
    SLCD->DR2  = 0;
    SLCD->DR3  = 0;
    SLCD->DR4  = 0;
    SLCD->DR5  = 0;
    SLCD->DR6  = 0;
    SLCD->DR7  = 0;
    SLCD->DR8  = 0;
    SLCD->DR9  = 0;
    SLCD->DR10 = 0;
    SLCD->DR11 = 0;
    SLCD->DR12 = 0;
    SLCD->DR13 = 0;
    SLCD->DR14 = 0;
    SLCD->DR15 = 0;
}
void LCD_WriteBit(uint8_t COMn, uint32_t Offset, uint32_t SEGn, uint8_t State)
{
    uint8_t Index = COMn * 2 + Offset;

    // if(State) SLCD->RAM[Index] |=  SEGn;
    // else      SLCD->RAM[Index] &= ~SEGn;

    switch(Index){
        case 0u:
            SLCD->DR0 = State ? (SLCD->DR0 | SEGn) : (SLCD->DR0 & ~SEGn);
            break;
        case 1u:
            SLCD->DR1 = State ? (SLCD->DR1 | SEGn) : (SLCD->DR1 & ~SEGn);
            break;
        case 2u:
            SLCD->DR2 = State ? (SLCD->DR2 | SEGn) : (SLCD->DR2 & ~SEGn);
            break;
        case 3u:
            SLCD->DR3 = State ? (SLCD->DR3 | SEGn) : (SLCD->DR3 & ~SEGn);
            break;
        case 4u:
            SLCD->DR4 = State ? (SLCD->DR4 | SEGn) : (SLCD->DR4 & ~SEGn);
            break;
        case 5u:
            SLCD->DR5 = State ? (SLCD->DR5 | SEGn) : (SLCD->DR5 & ~SEGn);
            break;
        case 6u:
            SLCD->DR6 = State ? (SLCD->DR6 | SEGn) : (SLCD->DR6 & ~SEGn);
            break;
        case 7u:
            SLCD->DR7 = State ? (SLCD->DR7 | SEGn) : (SLCD->DR7 & ~SEGn);
            break;
        case 8u:
            SLCD->DR8 = State ? (SLCD->DR8 | SEGn) : (SLCD->DR8 & ~SEGn);
            break;
        case 9u:
            SLCD->DR9 = State ? (SLCD->DR9 | SEGn) : (SLCD->DR9 & ~SEGn);
            break;
        case 10u:
            SLCD->DR10 = State ? (SLCD->DR10 | SEGn) : (SLCD->DR10 & ~SEGn);
            break;
        case 11u:
            SLCD->DR11 = State ? (SLCD->DR11 | SEGn) : (SLCD->DR11 & ~SEGn);
            break;                                                                                                                                    
        case 12u:
            SLCD->DR12 = State ? (SLCD->DR12 | SEGn) : (SLCD->DR12 & ~SEGn);
            break;                                                                                                                                    
        case 13u:
            SLCD->DR13 = State ? (SLCD->DR13 | SEGn) : (SLCD->DR13 & ~SEGn);
            break;                                                                                                                                    
        case 14u:
            SLCD->DR14 = State ? (SLCD->DR14 | SEGn) : (SLCD->DR14 & ~SEGn);
            break;                                                                                                                                    
        case 15u:
            SLCD->DR15 = State ? (SLCD->DR15 | SEGn) : (SLCD->DR15 & ~SEGn);
            break;                                                                                                                                                
    }
}

uint8_t LCD_SearchCode(char ch)
{
    uint8_t i;
    for(i = 0; i < 38; i++) {
        if(ch == LCD_CODE_Table[i].ch) {
            return LCD_CODE_Table[i].Data;
        }
    }

    return 0xFF;
}
void LCD_SearchName(char* str, uint8_t* COMn, uint8_t* SEGn)
{
    uint8_t i, j;
    for(i = 0; i < LCD_COM_NUMBER; i++) {
        for(j = 0; j < LCD_SEG_NUMBER; j++) {
            if(strcmp(str, LCD_NAME_Table[i][j]) == 0) {
                *COMn = i;
                *SEGn = j;
                return;
            }
        }
    }

    *COMn = 0xFF;
    *SEGn = 0xFF;
}
void LCD_DisplayNumber1(uint8_t Index, char ch, uint8_t Point)
{
    uint8_t i;
    char TAB[6][8][4] =  {
        {"5A ", "5B ", "5C ", "5D ", "5E ", "5F ", "5G ", "DP5"},
        {"6A ", "6B ", "6C ", "6D ", "6E ", "6F ", "6G ", "DP6"},
        {"7A ", "7B ", "7C ", "7D ", "7E ", "7F ", "7G ", "DP7"},
        {"8A ", "8B ", "8C ", "8D ", "8E ", "8F ", "8G ", "DP8"},
        {"9A ", "9B ", "9C ", "9D ", "9E ", "9F ", "9G ", "DP9"},
        {"10A", "10B", "10C", "10D", "10E", "10F", "10G", "   "},
    };

    uint8_t COMn = 0xFF, SEGn = 0xFF;

    uint8_t Code = LCD_SearchCode(ch);

    if(Code != 0xFF) {
        for(i = 0; i < 7; i++) {
            LCD_SearchName(TAB[Index][i], &COMn, &SEGn);

            if((COMn != 0xFF) && (SEGn != 0xFF)) {
                LCD_WriteBit(COMn, LCD_SEG_Table[SEGn][0], LCD_SEG_Table[SEGn][1], (Code >> i) & 0x01);
            }
        }

        LCD_SearchName(TAB[Index][7], &COMn, &SEGn);

        if((COMn != 0xFF) && (SEGn != 0xFF)) {
            LCD_WriteBit(COMn, LCD_SEG_Table[SEGn][0], LCD_SEG_Table[SEGn][1], Point);
        }
    }
}
void LCD_DisplayNumber2(uint8_t Index, char ch, uint8_t Point)
{
    uint8_t i;
    char TAB[4][8][4] = {
        {"1A ", "1B ", "1C ", "1D ", "1E ", "1F ", "1G ", "DP1"},
        {"2A ", "2B ", "2C ", "2D ", "2E ", "2F ", "2G ", "DP2"},
        {"3A ", "3B ", "3C ", "3D ", "3E ", "3F ", "3G ", "DP3"},
        {"4A ", "4B ", "4C ", "4D ", "4E ", "4F ", "4G ", "   "},
    };

    uint8_t COMn = 0xFF, SEGn = 0xFF;

    uint8_t Code = LCD_SearchCode(ch);

    if(Code != 0xFF) {
        for(i = 0; i < 7; i++) {
            LCD_SearchName(TAB[Index][i], &COMn, &SEGn);

            if((COMn != 0xFF) && (SEGn != 0xFF)) {
                LCD_WriteBit(COMn, LCD_SEG_Table[SEGn][0], LCD_SEG_Table[SEGn][1], (Code >> i) & 0x01);
            }
        }

        LCD_SearchName(TAB[Index][7], &COMn, &SEGn);

        if((COMn != 0xFF) && (SEGn != 0xFF)) {
            LCD_WriteBit(COMn, LCD_SEG_Table[SEGn][0], LCD_SEG_Table[SEGn][1], Point);
        }
    }
}
void LCD_DisplayUnit(uint8_t Index, uint8_t State)
{
    //                 0-mV   1-N.m  2-kg   3-g    4-℃   5-(配置) 6-(电池) 7-(小:) 8-(大:1) 9-(大:2)
    char TAB[10][4] = {"S1 ", "S2 ", "S3 ", "S4 ", "S9 ", "T1 ", "W1 ", "C1 ", "C2 ", "C3 "};

    uint8_t COMn = 0xFF, SEGn = 0xFF;

    LCD_SearchName(TAB[Index], &COMn, &SEGn);

    if((COMn != 0xFF) && (SEGn != 0xFF)) {
        LCD_WriteBit(COMn, LCD_SEG_Table[SEGn][0], LCD_SEG_Table[SEGn][1], State);
    }
}

static uint32_t Number1  = 0;
static uint32_t Number2  = 0;
static uint32_t Counter  = 0;
static uint32_t Unit     = 0;
void LCD_DisplayDataUpdate(void)
{
    Number1 = (Number1 + 1) % 1000000;

    if(Number1 < 10) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, ' ', 0);
        LCD_DisplayNumber1(4, '0', 1);
        LCD_DisplayNumber1(5, '0' + Number1, 0);
    }
    else if(Number1 < 100) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, ' ', 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10) % 10), 1);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1 ) % 10), 0);
    }
    else if(Number1 < 1000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10 ) % 10), 1);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1  ) % 10), 0);
    }
    else if(Number1 < 10000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100 ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10  ) % 10), 1);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1   ) % 10), 0);
    }
    else if(Number1 < 100000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, '0' + ((Number1 / 10000) % 10), 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000 ) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100  ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10   ) % 10), 1);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1    ) % 10), 0);
    }
    else if(Number1 < 1000000) {
        LCD_DisplayNumber1(0, '0' + ((Number1 / 100000) % 10), 0);
        LCD_DisplayNumber1(1, '0' + ((Number1 / 10000 ) % 10), 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000  ) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100   ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10    ) % 10), 1);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1     ) % 10), 0);
    }

    Counter++;

    if((Counter % 100) == 0) {
        LCD_DisplayUnit(Unit, 0);

        Unit = (Unit + 1) % 10;

        LCD_DisplayUnit(Unit, 1);


        Number2 = (Number2 + 1) % 10000;

        if(Number2 < 10) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, ' ', 0);
            LCD_DisplayNumber2(2, ' ', 0);
            LCD_DisplayNumber2(3, '0' + Number2, 0);
        }
        else if(Number2 < 100) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, ' ', 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1 ) % 10), 0);
        }
        else if(Number2 < 1000) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, '0' + ((Number2 / 100) % 10), 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10 ) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1  ) % 10), 0);
        }
        else if(Number2 < 10000) {
            LCD_DisplayNumber2(0, '0' + ((Number2 / 1000) % 10), 0);
            LCD_DisplayNumber2(1, '0' + ((Number2 / 100 ) % 10), 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10  ) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1   ) % 10), 0);
        }
    }
}

void LCD_DisplayNumbers1(uint32_t Number)
{
    uint32_t Number1 = Number % 1000000;
    
    if(Number1 < 10) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, ' ', 0);
        LCD_DisplayNumber1(4, ' ', 0);
        LCD_DisplayNumber1(5, '0' + Number1, 0);
    }
    else if(Number1 < 100) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, ' ', 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10) % 10), 0);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1 ) % 10), 0);
    }
    else if(Number1 < 1000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, ' ', 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10 ) % 10), 0);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1  ) % 10), 0);
    }
    else if(Number1 < 10000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, ' ', 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100 ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10  ) % 10), 0);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1   ) % 10), 0);
    }
    else if(Number1 < 100000) {
        LCD_DisplayNumber1(0, ' ', 0);
        LCD_DisplayNumber1(1, '0' + ((Number1 / 10000) % 10), 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000 ) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100  ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10   ) % 10), 0);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1    ) % 10), 0);
    }
    else if(Number1 < 1000000) {
        LCD_DisplayNumber1(0, '0' + ((Number1 / 100000) % 10), 0);
        LCD_DisplayNumber1(1, '0' + ((Number1 / 10000 ) % 10), 0);
        LCD_DisplayNumber1(2, '0' + ((Number1 / 1000  ) % 10), 0);
        LCD_DisplayNumber1(3, '0' + ((Number1 / 100   ) % 10), 0);
        LCD_DisplayNumber1(4, '0' + ((Number1 / 10    ) % 10), 0);
        LCD_DisplayNumber1(5, '0' + ((Number1 / 1     ) % 10), 0);
    }
}

void LCD_DisplayNumbers2(uint32_t Number)
{
    uint32_t Number2 = Number % 10000;
    
    if(Number2 < 10) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, ' ', 0);
            LCD_DisplayNumber2(2, ' ', 0);
            LCD_DisplayNumber2(3, '0' + Number2, 0);
        }
        else if(Number2 < 100) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, ' ', 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1 ) % 10), 0);
        }
        else if(Number2 < 1000) {
            LCD_DisplayNumber2(0, ' ', 0);
            LCD_DisplayNumber2(1, '0' + ((Number2 / 100) % 10), 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10 ) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1  ) % 10), 0);
        }
        else if(Number2 < 10000) {
            LCD_DisplayNumber2(0, '0' + ((Number2 / 1000) % 10), 0);
            LCD_DisplayNumber2(1, '0' + ((Number2 / 100 ) % 10), 0);
            LCD_DisplayNumber2(2, '0' + ((Number2 / 10  ) % 10), 0);
            LCD_DisplayNumber2(3, '0' + ((Number2 / 1   ) % 10), 0);
        }
}

void LCD_DisplayFLoat1(double fNumber, uint8_t Point)
{
    uint32_t Number1 = (uint32_t)fNumber;
    uint32_t Decimals = 0;
    uint8_t pMax = 0;
    uint8_t pUse = 0;
    uint8_t iLen = 0;

    Number1 = Number1 % (uint32_t)POW10[LCD_NUM_LEN1];
    if(Point==0) {
        // 无小数
        LCD_DisplayNumbers1(Number1);
    }
    else {
        // 计算小数最大显示位数
        if(Number1 < 10) {
            iLen = 1;
        }
        else if(Number1 < 100) {
            iLen = 2;
        }
        else if(Number1 < 1000) {
            iLen = 3;
        }
        else if(Number1 < 10000) {
            iLen = 4;
        }
        else if(Number1 < 100000) {
            iLen = 5;
        }
        else if(Number1 < 1000000) {
            iLen = 6;
        }    
        pMax = LCD_NUM_LEN1 - iLen;
        pUse = Point <= pMax ? Point : pMax;

        if(pUse==0) {
            // 无小数
            LCD_DisplayNumbers1(Number1);
        } else {
            // 有小数位计算
            Decimals = (uint32_t)((fNumber - Number1) * POW10[pUse]);
            Number1 = Number1 * POW10[pUse] + Decimals;
            if(Number1==0) {
                LCD_DisplayNumbers1(0);
            }
            else {
                for(uint8_t i=0;i<LCD_NUM_LEN1;i++) {
                    if(i<iLen+pUse) {
                        LCD_DisplayNumber1(LCD_NUM_LEN1-1-i, '0' + Number1%10, i==pUse?1:0);
                        Number1 = Number1 / 10;
                    } else {
                        LCD_DisplayNumber1(LCD_NUM_LEN1-1-i, ' ', 0);
                    }
                }
            }
        }
    }
}

void LCD_DisplayFLoat2(double fNumber, uint8_t Point)
{
    uint32_t Number1 = (uint32_t)fNumber;
    uint32_t Decimals = 0;
    uint8_t pMax = 0;
    uint8_t pUse = 0;
    uint8_t iLen = 0;

    Number1 = Number1 % (uint32_t)POW10[LCD_NUM_LEN2];
    if(Point==0) {
        // 无小数
        LCD_DisplayNumbers2(Number1);
    }
    else {
        // 计算小数最大显示位数
        if(Number1 < 10) {
            iLen = 1;
        }
        else if(Number1 < 100) {
            iLen = 2;
        }
        else if(Number1 < 1000) {
            iLen = 3;
        }
        else if(Number1 < 10000) {
            iLen = 4;
        }
        pMax = LCD_NUM_LEN2 - iLen;
        pUse = Point <= pMax ? Point : pMax;

        if(pUse==0) {
            // 无小数
            LCD_DisplayNumbers2(Number1);
        } else {
            // 有小数位计算
            Decimals = (uint32_t)((fNumber - Number1) * POW10[pUse]);
            Number1 = Number1 * POW10[pUse] + Decimals;
            if(Number1==0) {
                LCD_DisplayNumbers2(0);
            }
            else {
                for(uint8_t i=0;i<LCD_NUM_LEN2;i++) {
                    if(i<iLen+pUse) {
                        LCD_DisplayNumber2(LCD_NUM_LEN2-1-i, '0' + Number1%10, i==pUse?1:0);
                        Number1 = Number1 / 10;
                    } else {
                        LCD_DisplayNumber2(LCD_NUM_LEN2-1-i, ' ', 0);
                    }
                }
            }
        }
    }
}